package ticket;

import java.io.FileOutputStream;
import java.util.Properties;

/**
 * 站点信息处理
 *
 * Created by forvoyager@outlook.com on 2018-10-08 16:03.
 */
public class StationCodeProcessor {
  /**
   * 拉取站点相关信息：站点编码、站点名称、站点首字母拼音等
   * key:value
   * 站点编码:站点名称|站点首字母拼音
   * @throws Exception
   */
  public void init() throws Exception {
    Properties pro = new Properties();

    String resp = TicketUtil.sendRequest(Constant.STATION_CODE_URL);

    String[] items = null;
    String[] stations = resp.substring(resp.indexOf("'")+1, resp.lastIndexOf("'")).split("@");
    for(String sts : stations){
      if(sts == null ||sts.length() == 0){continue;}
      items = sts.split("\\|");
      pro.put(items[2], items[1] + "|" + items[4]);
    }


    FileOutputStream code = new FileOutputStream(this.getClass().getClassLoader().getResource("").getPath() + "station_code.properties");
    pro.store(code, "站点信息");
    code.close();

    System.out.println("站点信息保存完毕");
  }
  public static void main(String[] args) throws Exception {
    new StationCodeProcessor().init();
  }
}
